//
//  LFCouponViewController.m
//  LoveFruit
//
//  Created by libbbb on 16/9/27.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFCouponViewController.h"
#import "LFCouponTopView.h"
#import "LFCouponTableViewCell.h"
#import "LFExpiredTableViewCell.h"

@interface LFCouponViewController ()<UITableViewDataSource>

@end

static NSString *expiredCell = @"expiredCell";
static NSString *cellID = @"discount_cellID";
@implementation LFCouponViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.navigationItem.title = @"优惠券";
    self.navigationController.navigationBar.translucent = NO;
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self action:@selector(go_back)];
    self.navigationItem.leftBarButtonItem = leftBarItem;
    [self setupUI];
}
-(void)go_back{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    
    [self.navigationController popViewControllerAnimated:YES];
}
//次方法会多次调用
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
    self.navigationController.navigationBar.hidden = NO;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 20;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        LFCouponTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        return cell;
        
    }
    LFExpiredTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:expiredCell forIndexPath:indexPath];
    return cell;
    
    
}


- (void)setupUI{
    
    
    LFCouponTopView *headView =[[LFCouponTopView alloc]init];
    
    [self.view addSubview:headView];
    
    
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self.view);
        make.height.equalTo(@40);
    }];
    
    UITableView *discountTableView = [[UITableView alloc]init];
    discountTableView.dataSource = self;
    
    discountTableView.rowHeight = 130;
    discountTableView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
    discountTableView.backgroundColor = [UIColor darkGrayColor];
    
    discountTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:discountTableView];
    
    [discountTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headView.mas_bottom);
        make.left.bottom.right.equalTo(self.view);
        
    }];
    [discountTableView registerClass:[LFCouponTableViewCell class] forCellReuseIdentifier:cellID];
    [discountTableView registerClass:[LFExpiredTableViewCell class] forCellReuseIdentifier:expiredCell];
}

@end
